package com.aura.lyngen.exception;

import lombok.Getter;

/**
 * 系统错误码枚举
 * 按照阿里巴巴开发手册规范设计
 * 错误码格式：A B C DD
 * A - 系统模块（1-9）
 * B - 错误级别（0-9）
 * C - 业务类型（0-9）
 * DD - 具体错误（00-99）
 */
@Getter
public enum ErrorCode {

    // ================================ 通用成功码 ================================
    SUCCESS(0, "操作成功"),

    // ================================ 通用客户端错误 (40xxx) ================================
    // 4000x - 请求参数错误
    PARAMS_ERROR(40000, "请求参数错误"),
    PARAMS_NULL(40001, "必填参数为空"),
    PARAMS_INVALID_FORMAT(40002, "参数格式不正确"),
    PARAMS_OUT_OF_RANGE(40003, "参数值超出允许范围"),
    PARAMS_LENGTH_EXCEEDED(40004, "参数长度超出限制"),
    PARAMS_TYPE_MISMATCH(40005, "参数类型不匹配"),
    PARAMS_DUPLICATE(40006, "参数重复"),
    PARAMS_COMBINATION_INVALID(40007, "参数组合无效"),

    // 4001x - 认证授权错误
    NOT_LOGIN_ERROR(40100, "用户未登录"),
    NO_AUTH_ERROR(40101, "无权限访问"),
    TOKEN_EXPIRED(40102, "登录已过期，请重新登录"),
    TOKEN_INVALID(40103, "登录状态无效"),
    LOGIN_FAILED(40104, "用户名或密码错误"),
    ACCOUNT_LOCKED(40105, "账户已被锁定"),
    ACCOUNT_DISABLED(40106, "账户已被禁用"),
    PERMISSION_DENIED(40107, "权限不足"),
    ROLE_NOT_FOUND(40108, "角色不存在"),

    // 4002x - 用户相关错误
    USER_NOT_FOUND(40200, "用户不存在"),
    USER_ALREADY_EXISTS(40201, "用户已存在"),
    USER_ACCOUNT_TOO_SHORT(40202, "用户账号过短，至少4位"),
    USER_PASSWORD_TOO_SHORT(40203, "密码过短，至少8位"),
    USER_PASSWORD_MISMATCH(40204, "两次输入的密码不一致"),
    USER_REGISTRATION_FAILED(40205, "用户注册失败"),
    USER_UPDATE_FAILED(40206, "用户信息更新失败"),
    USER_DELETE_FAILED(40207, "用户删除失败"),
    USER_ACCOUNT_INVALID(40208, "用户账号格式不正确"),
    USER_PASSWORD_WEAK(40209, "密码强度不够"),

    // 4003x - 资源禁止访问
    FORBIDDEN_ERROR(40300, "禁止访问"),
    RESOURCE_ACCESS_DENIED(40301, "资源访问被拒绝"),
    OPERATION_NOT_ALLOWED(40302, "操作不被允许"),
    TIME_WINDOW_RESTRICTED(40303, "当前时间段禁止操作"),
    IP_ACCESS_DENIED(40304, "IP地址访问被拒绝"),

    // 4004x - 资源不存在错误
    NOT_FOUND_ERROR(40400, "请求的资源不存在"),
    APP_NOT_FOUND(40401, "应用不存在"),
    FILE_NOT_FOUND(40402, "文件不存在"),
    API_NOT_FOUND(40403, "接口不存在"),
    CONFIG_NOT_FOUND(40404, "配置不存在"),
    DATA_NOT_FOUND(40405, "数据不存在"),
    ROUTE_NOT_FOUND(40406, "路由不存在"),

    // 4005x - 业务状态冲突
    CONFLICT_ERROR(40500, "资源冲突"),
    DATA_VERSION_CONFLICT(40501, "数据版本冲突"),
    RESOURCE_ALREADY_EXISTS(40502, "资源已存在"),
    STATUS_CONFLICT(40503, "状态冲突"),
    OPERATION_CONFLICT(40504, "操作冲突"),

    // 4006x - 应用相关错误
    APP_CREATE_FAILED(40600, "应用创建失败"),
    APP_UPDATE_FAILED(40601, "应用更新失败"),
    APP_DELETE_FAILED(40602, "应用删除失败"),
    APP_DEPLOY_FAILED(40603, "应用部署失败"),
    APP_CODE_NOT_GENERATED(40604, "应用代码未生成"),
    APP_NAME_INVALID(40605, "应用名称无效"),
    APP_TYPE_UNSUPPORTED(40606, "不支持的应用类型"),
    APP_PERMISSION_DENIED(40607, "无权限操作该应用"),
    APP_STATUS_INVALID(40608, "应用状态无效"),

    // 4007x - AI代码生成相关错误
    AI_PROMPT_EMPTY(40700, "AI提示词不能为空"),
    AI_CODE_GEN_TYPE_INVALID(40701, "代码生成类型无效"),
    AI_MODEL_UNAVAILABLE(40702, "AI模型不可用"),
    AI_RESPONSE_INVALID(40703, "AI响应格式无效"),
    AI_TOKEN_LIMIT_EXCEEDED(40704, "AI对话长度超出限制"),
    AI_REQUEST_TIMEOUT(40705, "AI请求超时"),
    AI_QUOTA_EXCEEDED(40706, "AI使用配额已用完"),
    AI_CONTENT_FILTERED(40707, "AI内容被过滤"),
    AI_SERVICE_UNAVAILABLE(40708, "AI服务不可用"),

    // 4008x - 文件操作相关错误
    FILE_UPLOAD_FAILED(40800, "文件上传失败"),
    FILE_DOWNLOAD_FAILED(40801, "文件下载失败"),
    FILE_DELETE_FAILED(40802, "文件删除失败"),
    FILE_TOO_LARGE(40803, "文件大小超出限制"),
    FILE_TYPE_NOT_SUPPORTED(40804, "不支持的文件类型"),
    FILE_CORRUPTED(40805, "文件已损坏"),
    FILE_PATH_INVALID(40806, "文件路径无效"),
    FILE_PERMISSION_DENIED(40807, "文件权限不足"),
    FILE_COMPRESSION_FAILED(40808, "文件压缩失败"),
    FILE_EXTRACTION_FAILED(40809, "文件解压失败"),

    // 4009x - 项目下载相关错误
    PROJECT_PATH_EMPTY(40900, "项目路径不能为空"),
    PROJECT_PATH_NOT_EXISTS(40901, "项目路径不存在"),
    PROJECT_PATH_NOT_DIRECTORY(40902, "项目路径不是目录"),
    PROJECT_DOWNLOAD_NAME_EMPTY(40903, "下载文件名不能为空"),
    PROJECT_PACKAGING_FAILED(40904, "项目打包失败"),

    // 4291x - 频率限制错误
    TOO_MANY_REQUEST(42900, "请求过于频繁"),
    RATE_LIMIT_EXCEEDED(42901, "请求频率超出限制"),
    CONCURRENT_LIMIT_EXCEEDED(42902, "并发数超出限制"),
    API_CALL_LIMIT_EXCEEDED(42903, "API调用次数超出限制"),
    USER_OPERATION_TOO_FREQUENT(42904, "用户操作过于频繁"),
    IP_REQUEST_TOO_FREQUENT(42905, "IP请求过于频繁"),

    // ================================ 服务端错误 (50xxx) ================================
    // 5000x - 通用系统错误
    SYSTEM_ERROR(50000, "系统内部异常"),
    OPERATION_ERROR(50001, "操作失败"),
    SERVICE_UNAVAILABLE(50002, "服务暂时不可用"),
    SYSTEM_BUSY(50003, "系统繁忙，请稍后重试"),
    SYSTEM_MAINTENANCE(50004, "系统维护中"),
    CONFIGURATION_ERROR(50005, "系统配置错误"),
    RESOURCE_EXHAUSTED(50006, "系统资源不足"),
    TIMEOUT_ERROR(50007, "操作超时"),

    // 5001x - 数据库相关错误
    DATABASE_ERROR(50100, "数据库异常"),
    DATABASE_CONNECTION_FAILED(50101, "数据库连接失败"),
    DATABASE_QUERY_FAILED(50102, "数据库查询失败"),
    DATABASE_UPDATE_FAILED(50103, "数据库更新失败"),
    DATABASE_TRANSACTION_FAILED(50104, "数据库事务失败"),
    DATABASE_CONSTRAINT_VIOLATION(50105, "数据库约束违反"),
    DATABASE_DEADLOCK(50106, "数据库死锁"),
    DATABASE_TIMEOUT(50107, "数据库操作超时"),

    // 5002x - 缓存相关错误
    CACHE_ERROR(50200, "缓存异常"),
    CACHE_CONNECTION_FAILED(50201, "缓存连接失败"),
    CACHE_OPERATION_FAILED(50202, "缓存操作失败"),
    CACHE_KEY_NOT_FOUND(50203, "缓存键不存在"),
    CACHE_SERIALIZATION_FAILED(50204, "缓存序列化失败"),
    CACHE_EVICTION_FAILED(50205, "缓存清除失败"),

    // 5003x - 外部服务调用错误
    EXTERNAL_SERVICE_ERROR(50300, "外部服务异常"),
    THIRD_PARTY_API_ERROR(50301, "第三方API调用失败"),
    AI_SERVICE_ERROR(50302, "AI服务异常"),
    CLOUD_STORAGE_ERROR(50303, "云存储服务异常"),
    SMS_SERVICE_ERROR(50304, "短信服务异常"),
    EMAIL_SERVICE_ERROR(50305, "邮件服务异常"),
    PAYMENT_SERVICE_ERROR(50306, "支付服务异常"),

    // 5004x - 截图相关错误
    SCREENSHOT_ERROR(50400, "截图功能异常"),
    BROWSER_INIT_FAILED(50401, "浏览器初始化失败"),
    WEBPAGE_LOAD_FAILED(50402, "网页加载失败"),
    SCREENSHOT_CAPTURE_FAILED(50403, "截图捕获失败"),
    IMAGE_COMPRESSION_FAILED(50404, "图片压缩失败"),
    IMAGE_SAVE_FAILED(50405, "图片保存失败"),
    SELENIUM_DRIVER_ERROR(50406, "Selenium驱动异常"),

    // 5005x - 代码生成相关错误
    CODE_GENERATION_ERROR(50500, "代码生成异常"),
    CODE_PARSING_FAILED(50501, "代码解析失败"),
    CODE_SAVE_FAILED(50502, "代码保存失败"),
    CODE_COMPILATION_FAILED(50503, "代码编译失败"),
    CODE_TEMPLATE_ERROR(50504, "代码模板异常"),
    VUE_PROJECT_BUILD_FAILED(50505, "Vue项目构建失败"),
    PROJECT_STRUCTURE_ERROR(50506, "项目结构异常"),

    // 5006x - 消息队列相关错误
    MESSAGE_QUEUE_ERROR(50600, "消息队列异常"),
    MESSAGE_SEND_FAILED(50601, "消息发送失败"),
    MESSAGE_CONSUME_FAILED(50602, "消息消费失败"),
    QUEUE_CONNECTION_FAILED(50603, "队列连接失败"),

    // 5007x - 限流和并发控制错误
    RATE_LIMITER_ERROR(50700, "限流器异常"),
    CONCURRENT_CONTROL_ERROR(50701, "并发控制异常"),
    LOCK_ACQUISITION_FAILED(50702, "锁获取失败"),
    DISTRIBUTED_LOCK_ERROR(50703, "分布式锁异常"),

    // 5008x - 文件系统相关错误
    FILE_SYSTEM_ERROR(50800, "文件系统异常"),
    DISK_SPACE_INSUFFICIENT(50801, "磁盘空间不足"),
    FILE_IO_ERROR(50802, "文件IO异常"),
    DIRECTORY_CREATE_FAILED(50803, "目录创建失败"),
    FILE_CLEANUP_FAILED(50804, "文件清理失败"),

    // 5009x - 网络通信相关错误
    NETWORK_ERROR(50900, "网络异常"),
    CONNECTION_TIMEOUT(50901, "连接超时"),
    READ_TIMEOUT(50902, "读取超时"),
    WRITE_TIMEOUT(50903, "写入超时"),
    NETWORK_UNREACHABLE(50904, "网络不可达"),
    SSL_HANDSHAKE_FAILED(50905, "SSL握手失败")
    ;


    /**
     * 状态码
     */
    private final int code;

    /**
     * 信息
     */
    private final String message;

    ErrorCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

}